
(in-package :clml.test)

(define-test test-changefinder
    (let (ts cf)
      (assert
       (setf ts (time-series-data
                 (read-data-from-file
                  (clml.utility.data:fetch "https://mmaul.github.io/clml.data/sample/traffic-balance.csv")
                  :type :csv
                  :csv-type-spec (cons 'string
                                       (make-list 6 :initial-element 'double-float))
                  :external-format :utf-8)
                 :except '(0) :time-label 0)))
      (assert-equality #'= 1015 (length (ts-points ts)))
      #- allegro (assert (setf cf (init-changefinder (sub-ts ts :start 0 :end 24)
                                               :score-type :log
                                               :ts-wsize 5 :score-wsize 5 :sdar-k 4
                                               :discount 0.005d0)))
      #- allegro (mapcar (lambda (v1 v2) (assert-equality #'epsilon> v2 v1))
              (loop for p across (ts-points (sub-ts ts :start 600 :end 700))
                    as new-dvec = (ts-p-pos p)
                    collect (update-changefinder cf new-dvec))
              '(-1.3836456347102382d0 -1.383645637970232d0  -1.3836456404202275d0
                -1.383645641800225d0  -1.3836456425602235d0 -1.3836456414502256d0
                -1.3836456375702328d0 -1.3836456330102413d0 -1.3836456286302496d0
                -1.383645619460267d0  -1.3836456025802997d0 -1.3836455765803517d0
                -1.383645542480422d0  -1.3836454971805179d0 -1.3836454457906306d0
                -1.3836453985407378d0 -1.383645363520819d0  -1.3836453367908819d0
                -1.3836453193109244d0 -1.3836453092309495d0 -1.3836453009209706d0
                -1.3836452910509955d0 -1.3836452798310244d0 -1.383645264161065d0
                -1.3836452469911105d0 -1.3836452255811678d0 -1.3836451982212425d0
                -1.383645169671321d0  -1.383645146681385d0  -1.3836451283214368d0
                -1.3836451148614755d0 -1.3836451042715066d0 -1.3836450914615444d0
                -1.3836450758915904d0 -1.3836450565816487d0 -1.383645035641712d0
                -1.3836450098417923d0 -1.3836449024121744d0 -1.383644597473572d0
                -1.3836429237027696d0 -1.3836368944534705d0 -1.3836222136585479d0
                -1.3835947574005916d0 -1.383548357190609d0  -1.383480810309154d0
                -1.3833963454810592d0 -1.3833018471906857d0 -1.3832046350029756d0
                -1.3831149298302d0    -1.38304030973923d0   -1.3829813438434972d0
                -1.3829361778807088d0 -1.3829022257854755d0 -1.3828760485396963d0
                -1.3828540312182218d0 -1.382834611843709d0  -1.3828173399823789d0
                -1.3828019842729347d0 -1.3827883706748585d0 -1.3827761975317505d0
                -1.3827655957573997d0 -1.3827566153754685d0 -1.382749176895584d0
                -1.3827431016531526d0 -1.382738245230025d0  -1.3827343398843623d0
                -1.382731181803096d0  -1.3827286077208507d0 -1.3827265154463897d0
                -1.3827248331652913d0 -1.382723495823213d0  -1.382722450324995d0
                -1.3827217469556714d0 -1.3827214668837637d0 -1.3827216319883728d0
                -1.382722280529322d0  -1.3827234011691216d0 -1.382724947286555d0
                -1.3827268370759587d0 -1.3827289746268228d0 -1.3827312673716767d0
                -1.382733664835002d0  -1.3827361126777369d0 -1.3827385913767323d0
                -1.3827411565519856d0 -1.3827438703226886d0 -1.3827467580254638d0
                -1.3827498315213964d0 -1.3827530774172385d0 -1.3827564586923176d0
                -1.3827599255280298d0 -1.3827634298510887d0 -1.3827669442804915d0
                -1.3827704687967832d0 -1.3827739913016024d0 -1.3827775209992372d0
                -1.3827810928093558d0 -1.3827847370104642d0 -1.3827884441700709d0
                -1.3827922122027534d0 -1.3827960145195313d0))))
